#ifndef D_TRIANGLE_H
#define D_TRIANGLE_H

#include <helpers\math\vector3.h>
#include <helpers\math\plane.h>

namespace DelGE
{
	namespace Helpers
	{
		namespace Math
		{
			class Triangle
			{
			private:
				Vector3 point[3];

			public:
				Triangle();
				Triangle(const Vector3& rPoint0, const Vector3& rPoint1, const Vector3& rPoint2);
				~Triangle();

				Vector3 GetPoint0() const;
				Vector3 GetPoint1() const;
				Vector3 GetPoint2() const;
				
				void SetPoint(int iIndex, const Vector3& rPosition);

				Vector3 GetNormal() const;
				Plane GetPlane() const;
			};

			inline Vector3 Triangle::GetPoint0() const
			{
				return this->point[0];
			}

			inline Vector3 Triangle::GetPoint1() const
			{
				return this->point[1];
			}

			inline Vector3 Triangle::GetPoint2() const
			{
				return this->point[2];
			}

			inline void Triangle::SetPoint(int iIndex, const Vector3& rPosition)
			{
				if (iIndex >= 0 && iIndex <= 2)
					this->point[iIndex] = rPosition;

				throw ("Index out of bounds!");
			}

			inline Vector3 Triangle::GetNormal() const
			{
				Vector3 vec0, vec1;

				vec0 = point[1] - point[0];
				vec1 = point[2] - point[0];

				return vec0.CrossProduct(vec1);
			}

			inline Plane Triangle::GetPlane() const
			{
				Plane trianglePlane;

				trianglePlane = Plane();
				trianglePlane.SetNormal(this->GetNormal());
				trianglePlane.SetDistanceFromOrigin(0);

				return trianglePlane;
			}
		}
	}
}

#endif